package com.jl15988.chainlog.util;

/**
 * 字符串工具
 *
 * @author Jalon
 * @since 2025/9/30 14:52
 **/
public class StrUtil {

    /**
     * 截断字符串，截断后追加
     *
     * @param str       字符串
     * @param maxLength 最大长度
     * @param appends   截断后追加的内容
     * @return 截断后的字符串
     */
    public static String truncateString(String str, int maxLength, String... appends) {
        if (str == null || str.length() <= maxLength) {
            return str;
        }
        StringBuilder append = new StringBuilder();
        if (appends != null && appends.length > 0) {
            for (String s : appends) {
                append.append(s);
            }
        }
        return str.substring(0, maxLength) + append;
    }
}
